﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.XSchEmA.Entity;

namespace Pixysoft.Framework.XSchEmA.Comparer
{
    /// <summary>
    /// 表名、字段个数、字段名
    /// </summary>
    class ColumnComparer : IColumnCompareResult
    {
        List<ColumnSchema> aSuplusColumns = new List<ColumnSchema>();
        List<ColumnSchema> bSuplusColumns = new List<ColumnSchema>();
        List<KeyValuePair<ColumnSchema, ColumnSchema>> sameColumns =
            new List<KeyValuePair<ColumnSchema, ColumnSchema>>();

        public IColumnCompareResult Compare(TableSchema aTable, TableSchema bTable)
        {
            foreach (ColumnSchema aColumn in aTable.Columns)
            {
                ColumnSchema bColumn = bTable.GetColumn(aColumn.ColumnName);
                if (bColumn != null)
                    sameColumns.Add(new KeyValuePair<ColumnSchema, ColumnSchema>(aColumn, bColumn));
                else
                    aSuplusColumns.Add(aColumn);
            }

            foreach (ColumnSchema bColumn in bTable.Columns)
            {
                ColumnSchema aColumn = aTable.GetColumn(bColumn.ColumnName);
                if (aColumn != null)
                    continue;
                else
                    bSuplusColumns.Add(bColumn);
            }

            return this;
        }


        public bool IsSame
        {
            get { return aSuplusColumns.Count == 0 && BSuplusColumns.Count == 0; }
        }

        public List<ColumnSchema> ASuplusColumns
        {
            get { return aSuplusColumns; }
        }

        public List<ColumnSchema> BSuplusColumns
        {
            get { return bSuplusColumns; }
        }

        public List<KeyValuePair<ColumnSchema, ColumnSchema>> SameColumns
        {
            get { return sameColumns; }
        }

    }
}
